import java.util.Arrays;
import java.util.Comparator;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-12-23
 * Time:15:30
 */

class AgeComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.getAge() - o2.getAge();
    }
}

class NameComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.getName().compareTo(o2.getName());
    }
}

class ScoreComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return (int) (o1.getScore()-o2.getScore());
    }
}
class Student  /*implements Comparable<Student*/{
    private   String name;
    private int age;
    private double score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

//    @Override
//    public int compareTo(Student o) {
//        return this.age - o.age;
//    }
}
public class TestDemo {
    public static void main(String[] args) {
//        Student student = new Student("xie",19,90.9);
//        System.out.println(student);
        Student[] students = new Student[3];
        students[0] = new Student("xie",28,99.9);
        students[1] = new Student("chao",18,89.9);
        students[2] = new Student("bang",19,79.9);
        System.out.println(Arrays.toString(students));
        AgeComparator ageComparator = new AgeComparator();
        Arrays.sort(students,ageComparator);
        System.out.println(Arrays.toString(students));
        NameComparator nameComparator = new NameComparator();
        Arrays.sort(students,nameComparator);
        System.out.println(Arrays.toString(students));

        ScoreComparator scoreComparator = new ScoreComparator();
        Arrays.sort(students,scoreComparator);
        System.out.println(Arrays.toString(students));
    }
    public static void mainComparable(String[] args) {
        Student student = new Student("xie",19,90.9);
        System.out.println(student);
        Student[] students = new Student[3];
        students[0] = new Student("xie",28,99.9);
        students[1] = new Student("chao",18,89.9);
        students[2] = new Student("bang",19,79.9);
        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
    public static void main1(String[] args) {
        int[] array = {19,3,2,18,7,4};
        System.out.println(Arrays.toString(array));
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
